/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2024-05-02 22:59:31
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2024-05-31 12:29:30
 * @FilePath: /hw/110/pipe/Shm_ipc/ShmClient.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "Comm.hpp"
#include"Fifo.hpp"
#include <unistd.h>

int main()
{
    //写端
    key_t key = GetShmKey();
    // cout<<"key:"<<GetShmKey()<<endl;
    cout << "key:" << Tohex(key) << endl;
    int shmid = GetShm(key, defaultsize);
    cout << "shmid:" << shmid << endl;
    char *addr = (char *)ShmAttach(shmid);
    cout << "Attach shm success, addr:" << Tohex((uint64_t)addr) << endl;

    memset(addr,0,defaultsize);//初始化缓冲区

    Sync syn;
    syn.OpenWriteOrDie();
    cout<<"Ready to Write..."<<endl;
    sleep(1);
    for (char c = 'A'; c < 'Z'; c++)
    {
        addr[c - 'A'] = c;
        sleep(1);
        syn.WakeUp();
    }

    sleep(10);
    // 去挂接
    Detach(addr);
    cout << "Detach success" << endl;
    // 3.删除共享内存
    sleep(10);
    //客服端不需要删除管道
    return 0;
}